<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>bootstrap datatable demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel="stylesheet" type="text/css"
	href="<%=basePath%>/mallstyle/css/bootstrap.min2.css">
<link rel="stylesheet" type="text/css"
	href="http://sandbox.runjs.cn/uploads/rs/238/n8vhm36h/bootstrap-responsiv.css">


<link rel="stylesheet" type="text/css"
	href="http://sandbox.runjs.cn/uploads/rs/238/n8vhm36h/dataTables.bootstra.css">
<link rel="stylesheet" href="<%=basePath%>/mallstyle/css/bootstrap.min.css" />
<link rel="stylesheet" href="<%=basePath%>/mallstyle/css/bootstrap-theme.min.css" />
<script type="text/javascript"
	src="<%=basePath%>/mallstyle/js/jquery-3.0.0.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/mallstyle/js/bootstrap.min.js"></script>

</head>

<body>

	<div class="container-fluid">
		<div class="row-fluid">
			<div>
				<ul class="breadcrumb">
					<li>商品信息管理 <span class="divider">></span>
					</li>
					<li>商品信息查看</li>
				</ul>
			</div>
		</div>
      <div style="padding-bottom: 20px">
			<button class="btn btn-primary" data-toggle="modal"
				data-target="#myModal">添加新商品</button>
			<%@include file="../goods/addGoods.jsp"%>
			<%@include file="../goods/editGoods.jsp"%>
			<%@include file="../goods/addCount.jsp"%>
		</div>
		<div class="row-fluid">

			<table
				class="table table-striped table-bordered table-hover datatable">
				<thead>
					<tr>
						<c:set value="${fn:split(pageModel.th_list,',') }" var="ths"></c:set>
						<c:forEach items="${ths }" var="th">
							<th>${th }</th>
						</c:forEach>
					</tr>
				</thead>
				<tbody>
					<!-- 数据信息 -->
					<c:forEach items="${list}" var="tds" varStatus="status">
						<tr class="odd gradeX">
							<td>${status.index + 1}</td>
							<td><img alt=""
								src="<%=path%>${tds.gPicture }" width="50px" height="50px"></td>
							<td>${tds.gName }</td>
							<td>${tds.gDetail }</td>
							<td>${tds.catCid }</td>
							<td>${tds.gPrice }</td>
							<td>${tds.gCount }</td>
							<td>
							<c:if test="${tds.gStatus==0 }">
							<font color="orange">下架</font>
							</c:if>
							<c:if test="${tds.gStatus==1 }">
							<font color="green">有货</font>
							</c:if>
							<c:if test="${tds.gStatus==2 }">
							<font color="red">无货</font>
							</c:if>
							</td>
							<td>
							<c:if test="${tds.gStatus==0}">
								<a href="<%=path %>/rest/goods/updateStatus?gid=${tds.gId }&status=1">上架</a>
							    <a href="<%=path %>/rest/goods/deleteGoods?gid=${tds.gId }">删除</a>
								<!--  <a href="<%=path %>/rest/goods/editGoods?gid=${tds.gId }">修改商品信息</a>-->
								 <a href="javascript:void(0)" onclick="update(this,${tds.gId });">修改商品信息</a> 
							</c:if>
							<c:if test="${tds.gStatus==1 }">
								<!--<a href="<%=path %>/rest/goods/updateStatus?gid=${tds.gId }&status=1">补货</a>-->
								<a href="javascript:void(0)" onclick="addCount(this,${tds.gId });">补货</a>
								<a href="<%=path %>/rest/goods/updateStatus?gid=${tds.gId }&status=0">下架</a>
								<!--  <a href="<%=path %>/rest/goods/editGoods?gid=${tds.gId }">修改商品信息</a>-->
								 <a href="javascript:void(0)" onclick="update(this,${tds.gId });">修改商品信息</a> 
							</c:if>									
							<c:if test="${tds.gStatus==2}">
								<!--<a href="<%=path %>/rest/goods/updateStatus?gid=${tds.gId }&status=1">补货</a>-->
								<a href="javascript:void(0)" onclick="addCount(this,${tds.gId });">补货</a>
								<a href="<%=path %>/rest/goods/updateStatus?gid=${tds.gId }&status=0">下架</a>
								<!--  <a href="<%=path %>/rest/goods/editGoods?gid=${tds.gId }">修改商品信息</a>-->
								 <a href="javascript:void(0)" onclick="update(this,${tds.gId });">修改商品信息</a> 
							</c:if>	
							</td>								
						</tr>
					</c:forEach>
				</tbody>
			</table>
		</div>
		<script type="text/javascript"
			src="http://sandbox.runjs.cn/uploads/rs/238/n8vhm36h/jquery.js"></script>
		<script type="text/javascript"
			src="http://sandbox.runjs.cn/uploads/rs/238/n8vhm36h/jquery.dataTables.js"></script>
		<script type="text/javascript"
			src="http://sandbox.runjs.cn/uploads/rs/238/n8vhm36h/bootstrap.min.js"></script>
		<script type="text/javascript"
			src="http://sandbox.runjs.cn/uploads/rs/238/n8vhm36h/dataTables.bootstrap.js"></script>
	</div>
	<script type="text/javascript">
		$(document).ready(function() {
    			$('.datatable').dataTable( {        				
        				"oLanguage": {
								"sUrl": "<%=path%>/json/zh_CN.json"
				}
			});
		});
	</script>
		<script type="text/javascript">
	function changeType(obj){
		$("#childList").empty();
		$("#echildList").empty();
		var id = obj.options[obj.selectedIndex].value;
		$.ajax({
        	url:"<%=path%>/rest/category/getCategoryTwoById?cid=" + id,
				contentType : "application/json;charset=UTF-8",
				dataType : "json",
				type : "post",
				async : true,
				success : function(result) {
				//	var jsonObj = eval("(" + result + ")");
				//	alert(result.json[0].rName);
					$.each(result.json, function(i, item) {
						jQuery("#childList").append(
								"<option value="+ item.catId+">" + item.catName + "</option>");
					});
					$.each(result.json, function(i, item) {
						jQuery("#echildList").append(
								"<option value="+ item.catId+">" + item.catName + "</option>");
					});
				},
				error : function(result) {
					alert("error");
					window.location.reload();
				}
			});
		}
	</script>
	<script>  
    function update(obj,id) {  
        var tds = $(obj).parent().parent().find('td');  
        $('#gId1').val(id);  
        $('#egName').val(tds.eq(2).text());  
        $('#egDetail').val(tds.eq(3).text());
        $('#egPrice').val(tds.eq(5).text());
        $('#egCount').val(tds.eq(6).text());
        $('#editModal').modal('show');  
    }  
    </script>
	<script>  
    function addCount(obj,id) {  
        var tds = $(obj).parent().parent().find('td');  
        $('#gId2').val(id);  
        $('#agName').val(tds.eq(2).text());  
        $('#agCount').val(tds.eq(6).text());  
        $('#addCount').modal('show');  
    }  
    </script>
</body>

</html>
